package com.glb.gilibuy.service.impl;

import com.glb.gilibuy.dao.ProductDiscussionDao;
import com.glb.gilibuy.entity.*;
import com.glb.gilibuy.service.ProductDiscussionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Description:
 * @Author: Yingtian qian
 * @Date: 2021/8/5 9:23
 */
@Service
public class ProductDiscussionServiceImpl implements ProductDiscussionService {
    @Autowired
    private ProductDiscussionDao productDiscussionDao;

    @Override
    public ProductDiscussion selectDiscussionByDiscussionId(String discussionId) {
        if (!"".equals(discussionId)) {
            ProductDiscussionExample productDiscussionExample = new ProductDiscussionExample();
            productDiscussionExample.or().andProductIdEqualTo(discussionId).andIsDeletedEqualTo(0);
            List<ProductDiscussion> productDiscussionList = productDiscussionDao.selectByExample(productDiscussionExample);
            if (productDiscussionList.isEmpty()) {
                return null;
            }
            return productDiscussionList.get(0);
        }
        return null;
    }

    @Override
    public List<ProductDiscussion> selectDiscussionsByProductId(String productId) {
        if (!"".equals(productId)) {
            ProductDiscussionExample productDiscussionExample = new ProductDiscussionExample();
            productDiscussionExample.setOrderByClause("id desc");
            productDiscussionExample.or().andProductIdEqualTo(productId).andIsDeletedEqualTo(0);
            List<ProductDiscussion> productDiscussionList = productDiscussionDao.selectByExample(productDiscussionExample);
            return productDiscussionList;
        }
        return null;
    }

}
